import Vue from 'vue'
import Vuex from 'vuex'
import axios from 'axios'

Vue.use(Vuex)

const store = new Vuex.Store({
	state: {
		cityId: '310100',
		cityName: '上海',
		isTabbarshow: true,
		cinemaList: [],
	},
	mutations: {
		changeCityName(state, name) {
			state.cityName = name
		},
		changeCityId(state, Id) {
			state.cityId = Id
		},
		hider(state) {
			state.isTabbarshow = false
		},
		show(state) {
			state.isTabbarshow = true
		},
		setCinemaList(state, value) {
			state.cinemaList = value
		},
		clearCinemaList(state) {
			state.cinemaList = []
		},
	},
	//异步
	actions: {
		getCinemaList(store, id) {
			axios({
				url: `/api/gateway?cityId=${id}&ticketFlag=1&k=6038055`,
				methods: 'get',
				headers: {
					'X-Client-Info':
						'{"a":"3000","ch":"1002","v":"5.2.1","e":"1676514945111647674859521","bc":"110100"}',
					'X-Host': 'mall.film-ticket.cinema.list',
				},
			}).then((res) => {
				// console.log(res, 123)
				// store.state.cinemaList = res.data.data.cinemas
				store.commit('setCinemaList', res.data.data.cinemas)
			})
		},
	},
})

export default store
